﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace EnterpriseFund.DAL
{
    /// <summary>
    /// 数据访问类:DJ_NSRXX_Extension2
    /// </summary>
    public partial class DJ_NSRXX_Extension2
    {
        public DJ_NSRXX_Extension2()
        { }
        #region  BasicMethod

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.DJ_NSRXX_Extension2 GetModel(decimal NSRDZDAH, string FEntityNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 NSRDZDAH,GS_NSRSBH,GS_NSRMC,FEntityNo,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP,FUpdEmplNo,FUpdDeptNo,FUpdDate,FUpdIP from fund.t_DJ_NSRXX_Extension2 ");
            strSql.Append(" where NSRDZDAH=@NSRDZDAH and FEntityNo=@FEntityNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,13),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)			};
            parameters[0].Value = NSRDZDAH;
            parameters[1].Value = FEntityNo;

            EnterpriseFund.Model.DJ_NSRXX_Extension2 model = new EnterpriseFund.Model.DJ_NSRXX_Extension2();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(EnterpriseFund.Model.DJ_NSRXX_Extension2 model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into fund.t_DJ_NSRXX_Extension2(");
            strSql.Append("NSRDZDAH,GS_NSRSBH,GS_NSRMC,FEntityNo,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP)");
            strSql.Append(" values (");
            strSql.Append("@NSRDZDAH,@GS_NSRSBH,@GS_NSRMC,@FEntityNo,@FInsEmpNo,@FInsDeptNo,@FInsDate,@FInsIP)");
            SqlParameter[] parameters = {
					new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,13),
					new SqlParameter("@GS_NSRSBH", SqlDbType.NVarChar,20),
					new SqlParameter("@GS_NSRMC", SqlDbType.NVarChar,80),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FInsEmpNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FInsDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FInsDate", SqlDbType.DateTime),
					new SqlParameter("@FInsIP", SqlDbType.NVarChar,15)};
            parameters[0].Value = model.NSRDZDAH;
            parameters[1].Value = model.GS_NSRSBH;
            parameters[2].Value = model.GS_NSRMC;
            parameters[3].Value = model.FEntityNo;
            parameters[4].Value = model.FInsEmpNo;
            parameters[5].Value = model.FInsDeptNo;
            parameters[6].Value = model.FInsDate;
            parameters[7].Value = model.FInsIP;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(EnterpriseFund.Model.DJ_NSRXX_Extension2 model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update fund.t_DJ_NSRXX_Extension2 set ");
            strSql.Append("GS_NSRSBH=@GS_NSRSBH,");
            strSql.Append("GS_NSRMC=@GS_NSRMC,");
            strSql.Append("FUpdEmplNo=@FUpdEmplNo,");
            strSql.Append("FUpdDeptNo=@FUpdDeptNo,");
            strSql.Append("FUpdDate=@FUpdDate,");
            strSql.Append("FUpdIP=@FUpdIP");
            strSql.Append(" where NSRDZDAH=@NSRDZDAH and FEntityNo=@FEntityNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@GS_NSRSBH", SqlDbType.NVarChar,20),
					new SqlParameter("@GS_NSRMC", SqlDbType.NVarChar,80),
					new SqlParameter("@FUpdEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FUpdDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FUpdDate", SqlDbType.VarChar,30),
					new SqlParameter("@FUpdIP", SqlDbType.VarChar,15),
					new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,13),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)};
            parameters[0].Value = model.GS_NSRSBH;
            parameters[1].Value = model.GS_NSRMC;
            parameters[2].Value = model.FUpdEmplNo;
            parameters[3].Value = model.FUpdDeptNo;
            parameters[4].Value = model.FUpdDate;
            parameters[5].Value = model.FUpdIP;
            parameters[6].Value = model.NSRDZDAH;
            parameters[7].Value = model.FEntityNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.DJ_NSRXX_Extension2 DataRowToModel(DataRow row)
        {
            EnterpriseFund.Model.DJ_NSRXX_Extension2 model = new EnterpriseFund.Model.DJ_NSRXX_Extension2();
            if (row != null)
            {
                if (row["NSRDZDAH"] != null && row["NSRDZDAH"].ToString() != "")
                {
                    model.NSRDZDAH = decimal.Parse(row["NSRDZDAH"].ToString());
                }
                if (row["GS_NSRSBH"] != null)
                {
                    model.GS_NSRSBH = row["GS_NSRSBH"].ToString();
                }
                if (row["GS_NSRMC"] != null)
                {
                    model.GS_NSRMC = row["GS_NSRMC"].ToString();
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FInsEmpNo"] != null)
                {
                    model.FInsEmpNo = row["FInsEmpNo"].ToString();
                }
                if (row["FInsDeptNo"] != null)
                {
                    model.FInsDeptNo = row["FInsDeptNo"].ToString();
                }
                if (row["FInsDate"] != null && row["FInsDate"].ToString() != "")
                {
                    model.FInsDate = DateTime.Parse(row["FInsDate"].ToString());
                }
                if (row["FInsIP"] != null)
                {
                    model.FInsIP = row["FInsIP"].ToString();
                }
                if (row["FUpdEmplNo"] != null)
                {
                    model.FUpdEmplNo = row["FUpdEmplNo"].ToString();
                }
                if (row["FUpdDeptNo"] != null)
                {
                    model.FUpdDeptNo = row["FUpdDeptNo"].ToString();
                }
                if (row["FUpdDate"] != null && row["FUpdDate"].ToString()!="")
                {
                    model.FUpdDate = DateTime.Parse(row["FUpdDate"].ToString());
                }
                if (row["FUpdIP"] != null)
                {
                    model.FUpdIP = row["FUpdIP"].ToString();
                }
            }
            return model;
        }

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

